package com.ke.forum.common.config;


import com.ke.forum.common.annotation.CheckEmail;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Pattern;

public class EmailValidator implements ConstraintValidator<CheckEmail, String> {

    private static final Pattern REAL_EMAIL = Pattern.compile("^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$");


    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {

        return REAL_EMAIL.matcher(s).matches();
    }
}

